/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.controller.administrator;

import carrello.impl.controller.AbstractCTRL;
import carrello.model.entities.User;
import java.util.List;
import static carrello.util.EntityManagerUtil.getEntityManager;
/**
 *
 * @author Usman
 */
public class ManageUsersCTRL extends AbstractCTRL{
    public static List<User> getAllUsers () {
        return User.getAllUsers ();
    }

    public static boolean updateUserPrivileges(List<User> users, String[] values) {
        int i = 0 ;
        if ( users == null || values == null )
            return false;
        if ( values.length != users.size() )
            return false;
        getEntityManager().beginUnitOfWork();
        for ( User u: users ) {
            u.setRole(values[i]);
            getEntityManager().update(u);
            ++i;
        }
        getEntityManager().endUnitOfWork();
        return true;
    }

    public static User getUserPrivileges(String sessionUsername) {
        return User.getUserByUserName(sessionUsername);
    }
}
 